package com.clstu.socket;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketTCP03Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        bufferedWriter.write("hello , server !!!（字符流）");
        bufferedWriter.newLine();//newLine() 可以结束通信 要求是对方也用readLine()接受数据
        bufferedWriter.flush();//调用这个方法才会将数据传入数据通道
        //socket.shutdownOutput();
        String readLine = bufferedReader.readLine();
        System.out.println(readLine);
        bufferedReader.close();
        bufferedWriter.close();
        socket.close();
    }
}
